<?php 
namespace app\admin\controller;
use think\Controller;
use think\facade\Session;
use auth\Auth;
/**
 * 
 */
class Base extends Controller{
	
	public function __construct() {
        parent::__construct();
        $this->adminInfo = [];
    	$this->admin_id = Session::get('admin_id');
        $this->getAdmin();
    }

    function getAdmin(){
        if(in_array(request()->action(),array('login','logout','verify')) || in_array(request()->controller(),array('Ueditor','Uploadify'))){
            //return;
        }else{
            if(!$this->admin_id){
                $this->error("用户信息已经过期，正在跳转登录页面",url('admin/index/login'));
                exit();
            }else{
                $this->adminInfo = db('administrator')->where('id = '.$this->admin_id)->find();
                $this->check();
            }
        }
    }

    function check(){
        if ($this->admin_id == 1) {
            return true;
        }
        $name = request()->module() . '/' . request()->controller() . '/' . request()->action();
        $auth = new Auth();
        $res = $auth->check($name,$this->admin_id);
        if(!$res){
            exit("您没有操作权限,请联系超级管理员分配权限");
        }
    }
}